package com.shandao.shangxiu.adapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;

import com.shandao.shangxiu.R;
import com.shandao.shangxiu.bean.entity.Banner;

import java.util.List;


/**
 * 首页广告viewpager适配器
 * @author king
 *
 */
public class HomePagerViewPagerAdapter extends PagerAdapter {

    private Context context;
    private List<Banner> datas;
    private boolean isInfiniteLoop;


    private int[] images = new int[] { R.mipmap.a, R.mipmap.b,
            R.mipmap.c, R.mipmap.d, R.mipmap.e, R.mipmap.f};

    public HomePagerViewPagerAdapter(Context context, List<Banner> datas) {
        this.context = context;
        this.datas = datas;
        isInfiniteLoop = false;
    }

    @Override
    public int getCount() {
        return images.length;
    }

    @Override
    public boolean isViewFromObject(View view, Object o) {
        return view == o;
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        ImageView view = new ImageView(container.getContext());
        view.setScaleType(ImageView.ScaleType.CENTER_CROP);
        view.setImageResource(images[position]);
        container.addView(view);
        return view;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }
}
